package com.ruoyi.example.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.example.mapper.DeviceMapper;
import com.ruoyi.example.domain.Device;
import com.ruoyi.example.service.IDeviceService;

import javax.annotation.Resource;

/**
 * 物联设备Service业务层处理
 *
 * @author ruoyi
 * @date 2023-04-10
 */
@Service
public class DeviceServiceImpl implements IDeviceService {
    @Resource
    private DeviceMapper deviceMapper;

    /**
     * 查询物联设备
     *
     * @param id 物联设备主键
     * @return 物联设备
     */
    @Override
    public Device selectDeviceById(Long id) {
        return deviceMapper.selectDeviceById(id);
    }

    /**
     * 查询物联设备列表
     *
     * @param device 物联设备
     * @return 物联设备
     */
    @Override
    public List<Device> selectDeviceList(Device device) {
        return deviceMapper.selectDeviceList(device);
    }

    /**
     * 新增物联设备
     *
     * @param device 物联设备
     * @return 结果
     */
    @Override
    public int insertDevice(Device device) {
        device.setCreateBy(SecurityUtils.getUsername());
        device.setCreateTime(DateUtils.getNowDate());
        return deviceMapper.insertDevice(device);
    }

    /**
     * 修改物联设备
     *
     * @param device 物联设备
     * @return 结果
     */
    @Override
    public int updateDevice(Device device) {
        device.setUpdateBy(SecurityUtils.getUsername());
        device.setUpdateTime(DateUtils.getNowDate());
        return deviceMapper.updateDevice(device);
    }

    /**
     * 批量删除物联设备
     *
     * @param ids 需要删除的物联设备主键
     * @return 结果
     */
    @Override
    public int deleteDeviceByIds(Long[] ids) {
        return deviceMapper.deleteDeviceByIds(ids);
    }

    /**
     * 删除物联设备信息
     *
     * @param id 物联设备主键
     * @return 结果
     */
    @Override
    public int deleteDeviceById(Long id) {
        return deviceMapper.deleteDeviceById(id);
    }
}
